<?php
namespace frontend\controllers;

use yii\base\Controller;
use frontend\models\Game;
use Yii;

class GameController extends Controller
{
    public function actionIndex()
    {
        $this->layout = false;
        return $this->render('index');
    }
    public  function actionContent()
    {
        $this->layout = 'game';
        $model = new Game(); 
        return $this->render('content',[
            'model' => $model,
        ]);
    }
    public function actionMessage() 
    {
        $this->layout = 'game';
        $model = new Game();
        if(Yii::$app->request->isPost){
            if($model->load(Yii::$app->request->post())&&$model->validate()){
                $change = Game::find()
                        ->where(['tel'=>$model->tel])
                        ->one();
                if(empty($change)){
                    $model->save();
                }else{
                    $change->name = $model->name;
                    $change->tel = $model->tel;
                    $change->save();
                }
                $num = count(Game::find()->all());
                return $this->render('index',[
                    'flag' => 1,
                    'num' => $num
                ]);
            }
        }else{
            return $this->render('index');
        }
    }
}